// 04myCenter/02set/01enterpriseSet/enterpriseSet.js
var co = require('../../../resource/js/common.js')
var M = require('../../../resource/js/md5.js')
var app = getApp()
var _this, _data,_opt
Page({

  /**
   * 页面的初始数据
   */
  data: {
     getSmsCodeText: '获取验证码',
     userInfo: "",
     //切换登录方式
     isThis: 0,
     // 登录方式错误提示信息
     isUserName: '',
     isPassWord: '',
     isPhoneNumber: '',
     isVerificationCode: '',
     // 短信验证码
     time: '获取验证码',
     currentTime: 120,
     smsCode: '',
     // 输入的手机号
     phoneNumber: '',
     tempPhone: '',
     // 传递信息
     replacePop: false, //更换手机确认按钮
     lastPwd: '', //旧支付密码
     newPwd: '', //新支付密码
     showMessage: false, //保存地址时候是否符合规格
     messageContent: '', //保存时未满足要求提示语
     firstSetPwd: '请输入旧支付密码',
     forInput: '',
     bizInfo:'',//商家信息
     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     _this = this
     _data = this.data
     _opt = options
     
     

  },
  //获取商家信息
  getBizInfo:function(){
     var url = 'jyhs/Admin/getInfo'
     co.getShareApi(url,{
        Biz_ID: _opt.Biz_ID
     },function(res){
        if(res.code == 0){
           console.log('res',res)
           _this.setData({
              bizInfo:res.data,
           })
           if (res.data.PayPassword_Is_Set == 0) {
              _this.setData({
                 firstSetPwd: '第一次不用输入',
                 forInput: 'disabled'
              })
           }
        }
     })

  },
   //获取旧支付密码
   inputLastPwd: function (e) {
      var lastPwd = e.detail.value
      _this.setData({
         lastPwd: lastPwd
      })
   },
   //获取新支付密码
   inputNewPwd: function (e) {
      var newPwd = e.detail.value
      _this.setData({
         newPwd: newPwd
      })
   },
   //确认修改
   modifyPassword:function(){
      var url = 'jyhs/Admin/setPassword'
      var param = {
         Biz_ID : _opt.Biz_ID,
         Biz_PayPassword : _data.lastPwd,
         Biz_New_PayPassword: _data.newPwd,
         type : 0
      }
      if (_data.newPwd == '') {
         //console.log(1)
         this.showMessage('新支付密码不能为空')
      } else if (_data.newPwd.length < 6) {
         //console.log(3)
         this.showMessage('新支付密码长度不能小于6')
      } else {
         //console.log(4)
         co.getShareApi(url, param, function (res) {
            if (res.code == 0) {
               co.toastAllText(res.msg)
               app.Data.userInfo = res.data
               setTimeout(function () {
                  var pages = getCurrentPages(),
                     prevPage = pages[pages.length - 2];
                  prevPage.setData({
                     alter: "123"
                  })
                  wx.navigateBack({})
               }, 1000)
            } else {
               co.toastAllText(res.msg)
            }
         })
      }
   },








   //跳转找回密码
   toRetrievePassword: function () {
      wx.navigateTo({
         url: '/04myCenter/02set/01enterpriseSet/enterpriseRetrievePassword/enterpriseRetrievePassword?Biz_ID='+_opt.Biz_ID,
      })
   },
   //显示提示信息
   showMessage: function (text) {
      var that = this
      that.setData({
         showMessage: true,
         messageContent: text
      })
      setTimeout(function () {
         that.setData({
            showMessage: true,
            messageContent: text
         })
         setTimeout(function () {
            that.setData({
               showMessage: false,
               messageContent: ''
            })
         }, 3000)
      })
   },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
     this.getBizInfo()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})